import * as actionType from './actionType.js'
import { getBeforeCredit, login, logout } from "../../http/daizhongApi"


export const getBeforeCreditAction = (data, count) => ({
    type: actionType.GETBEFORECREDIT,
    data,
    count
})
export const getBeforeCreditAsyncAction = (params) => (dispatch) =>
    getBeforeCredit(params)
    .then(res => {
        console.log(res);
        dispatch(getBeforeCreditAction(res.data.data, res.data.count))
    })
    .catch(err => {
        console.log(err);
    })



export const loginAction = (data) => ({
    type: actionType.LOGIN,
    data
})



export const loginAsyncAction = (params) => (dispatch) =>
    login(params)
    .then(res => {
        console.log(res);
        sessionStorage.setItem("token", res.data.token)
        sessionStorage.setItem("isLogin", true)
        console.log(res.data.data);
        dispatch(loginAction(res.data.data))
        if (res.data.code) {
            return Promise.resolve(res.data)
        }
    })
    .catch(err => {
        console.log(err);
    })

export const loginoutAsync = (params) => (dispatch) =>
    logout()
    .then(res => {
        console.log(res);
    })
    .catch(err => {
        console.log(err);
    })